package com.qf.controller;

import com.qf.entity.TbUser;
import com.qf.service.TbUserService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * (TbUser)表控制层
 *
 * @author makejava
 * @since 2021-04-06 09:44:32
 */
@RestController
@RequestMapping("tbUser")
public class TbUserController {
    /**
     * 服务对象
     */
    @Resource
    private TbUserService tbUserService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("selectOne")
    public TbUser selectOne(Integer id) {
        return this.tbUserService.queryById(id);
    }

    @GetMapping("queryAll")
    @ResponseBody
    public TbUser queryAll(String userName, String userPassword) {
        TbUser tbUser = new TbUser();
        tbUser.setUserName(userName);
        tbUser.setUserPassword(userPassword);
        List<TbUser> tbUsers = this.tbUserService.queryAll(tbUser);
        if (tbUsers.size() < 1) {
            TbUser tbUser1 = new TbUser();
            return tbUser1;
        } else {
            TbUser tbUser2 = new TbUser();
            for (TbUser user : tbUsers) {
                tbUser2 = user;
            }
            return tbUser2;
        }
    }

}